/*
 * tarm_communication.c
 *
 *  Created on: 2019��11��8��
 *      Author: AN
 */

#include "tarm_uart.h"

#include "tarm_communication.h"
#include "tarm_limit.h"
#include "tarm_pwm.h"
#include "tarm_baseTimer.h"

#include "application/tarm_run.h"
#include "application/tarm_init.h"
#include "application/tarm_command.h"

#include <stdlib.h>
#include <string.h>
#include <stdio.h>


unsigned int Esp8266_InitFlag=0;	//

/************************************************************
*	不断串口输出提醒输入命令；自动返回接收到的命令
*	传入参数：	无
*	返回值：	无
*	执行位置：	在main.c的
************************************************************/

void uart_tips(void)
{
//	uint16_t times=0;

	if(StructUart0RxBuf.FinishFlag==2)
	{
		//1-reshow the rec comment
		PRINTF_UART0("<uart0 rec:\n");
		PRINTF_UART0(StructUart0RxBuf.Rxbuf);
		PRINTF_UART0("<uart0 rec end>\r\n");

		//2-operate
		command_operate((uint8_t*)StructUart0RxBuf.Rxbuf, StructUart0RxBuf.RxbufSize);

		//3-clear the flag
		memset(StructUart0RxBuf.Rxbuf, 0, sizeof(StructUart0RxBuf.Rxbuf)/sizeof(char));
		StructUart0RxBuf.FinishFlag = 0;
		StructUart0RxBuf.RxbufSize = 0;

		//4-
	}
	else
	{
//		times++;
//		if(times%5000==0)
//		{
//			PRINTF_UART0("\r\n CNC_ARM \r\n");
//			PRINTF_UART0("CNC_ARM@day_day\r\n\r\n");
//		}
//		if(times%200==0)PRINTF_UART0("\nplease enter the command, end with enter");
//		delay_ms(10);
	}
}

void uart2_tips(void)
{
//	uint16_t times=0;
	//char report_str[20]="0";

	if(StructUart1RxBuf.FinishFlag==2)
	{
		//1-reshow the rec comment
		PRINTF_UART1("<uart1 rec:\n");
		PRINTF_UART1(StructUart1RxBuf.Rxbuf);
		PRINTF_UART1("<uart1 rec end>\r\n");

		//2-operate
		command_operate((uint8_t*)StructUart1RxBuf.Rxbuf, StructUart1RxBuf.RxbufSize);

		//3-clear the flag
		memset(StructUart1RxBuf.Rxbuf, 0, sizeof(StructUart1RxBuf.Rxbuf)/sizeof(char));
		StructUart1RxBuf.FinishFlag = 0;
		StructUart1RxBuf.RxbufSize = 0;

		//4-
	}
	else
	{
		delay_ms(10);
	}
}

int esp8266_init(char *esp_char)
{
	return 1;
}

int esp8266_report(void)
{
	return 1;
}


int esp8266_report_command(char *str,int len)
{
	return 1;
}

int console_report(void)
{
	char AT_String[25];
	char Report_String[100];
	int len_AT_String,len_Report_String;

	if(Esp8266_InitFlag != 1)
	{
		return -1;
	}

	sprintf(Report_String,"_&x:%f;\t_&y:%f;\n_&prime:%f;\t_&vice:%f;\r\r\n",
			g_TARM_RunRecord.pv_current.x,
			g_TARM_RunRecord.pv_current.y,
			g_TARM_RunRecord.pv_current.p,
			g_TARM_RunRecord.pv_current.v);
	len_Report_String = sizeof(Report_String) / sizeof(Report_String[0]);

	sprintf(AT_String,"AT+CIPSEND=0,%d\r\r\n",len_Report_String);
	len_AT_String = sizeof(AT_String) / sizeof(AT_String[0]);

	PRINTF_UART0OnSize(AT_String, len_AT_String);

	delay_ms(300);

	PRINTF_UART0OnSize(Report_String, len_Report_String);

	return 1;
}

int console_report_command(char *str,int len)
{
	PRINTF_UART0OnSize(str, len);
	return 1;
}

